package com.xiao.permission_system.controller;


import com.xiao.permission_system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import com.xiao.permission_system.entity.Role;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;

import org.springframework.web.bind.annotation.RestController;
import cn.xiao.permission_system.common.BaseController;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author beth
 * @since 2019-10-29
 */
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController {

        @Autowired
        private IRoleService iRoleService;

    /**
     * 新增
     */
    @ApiOperation(value = "新增数据")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public int add(@RequestBody Role entity){
        return iRoleService.insert(entity);
     }

     /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @RequestMapping(value = "/deleteById")
    public int deleteById(@RequestParam("id") String id){
        Integer result = iRoleService.deleteById(id);
        return result;
    }

    /**
     * 查询
     */
     @ApiOperation(value = "根据ID查询")
     @RequestMapping(value = "/selectById")
     public Role  selectById(@RequestParam("id") String id){
        Role  result = iRoleService.selectById(id);
        return result;
     }
      /**
       * 更新
       */
       @ApiOperation(value = "更新")
       @RequestMapping(value = "/updateById")
       public boolean updateById(@RequestBody Role updateById){
          boolean result = iRoleService.updateById(updateById);
          return result;
       }

      /**
       * 分页查询
       * @param page 分页信息
       * @param wrapper 查询条件
       * @return
       */
       public  IPage<Role> selectPage(Page<Role> page, @Param(Constants.WRAPPER) Wrapper<Role> wrapper) {
                 return iRoleService.selectPage(page,wrapper);
       }
}
